<?php


namespace app\model;




class ArticleModel extends BaseModel
{
    protected $table = 'forum_article';

    public function user(): \think\model\relation\HasMany
    {
        return $this->hasMany(UserModel::class, 'id', 'uid')
            ->field(['id', 'name']);
    }

    /**
     * @throws \app\libs\exception\NotFoundException
     * @throws \app\libs\exception\ServerError
     */
    public function find_add_pv($id)
    {
        $article = self::with(['user'])
            ->find($id);

        $this->isNoFound($article);

        $article->pv += 1;
        $article->save();
        return $article;
    }
}